home *** CD-ROM | disk | FTP | other *** search
- package Common
- {
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundMixer;
- import flash.media.SoundTransform;
-
- public class SoundManager
- {
-
- private static var instance:SoundManager;
-
-
- private var sounds:Array;
-
- private var sfxVolume:Number = 0.1;
-
- private var bgPlayingName:String = "";
-
- private var bgVolume:Number = 0.1;
-
- private var bgSoundChannel:SoundChannel;
-
- private var isMute:Boolean = false;
-
- private var isBGPlaying:Boolean = false;
-
- public function SoundManager()
- {
- sounds = [];
- sfxVolume = 0.1;
- bgVolume = 0.1;
- isMute = false;
- bgPlayingName = "";
- isBGPlaying = false;
- super();
- }
-
- public static function getInstance() : SoundManager
- {
- if(instance == null)
- {
- instance = new SoundManager();
- }
- return instance;
- }
-
- public function toggleMuteSound() : *
- {
- SoundMixer.stopAll();
- isMute = !isMute;
- }
-
- public function get BGVolume() : Number
- {
- return bgVolume;
- }
-
- public function playSoundFromRes(param1:String, param2:Sound, param3:uint) : *
- {
- var _loc4_:SoundTransform = null;
- if(isMute)
- {
- return;
- }
- _loc4_ = new SoundTransform();
- if(param3 == SoundObject.C_BG)
- {
- if(isBGPlaying && param1 == bgPlayingName)
- {
- return;
- }
- stopBG();
- _loc4_.volume = bgVolume;
- bgSoundChannel = param2.play(0,int.MAX_VALUE,_loc4_);
- bgPlayingName = param1;
- isBGPlaying = true;
- }
- else if(param3 == SoundObject.C_SFX)
- {
- _loc4_.volume = sfxVolume;
- param2.play(0,0,_loc4_);
- }
- }
-
- public function get SFXVolume() : Number
- {
- return sfxVolume;
- }
-
- public function set BGVolume(param1:Number) : *
- {
- bgVolume = param1;
- bgSoundChannel.soundTransform = new SoundTransform(param1);
- }
-
- public function purgeSound(param1:String) : *
- {
- sounds[param1] = null;
- }
-
- public function stopBG() : *
- {
- if(bgSoundChannel != null)
- {
- bgSoundChannel.stop();
- isBGPlaying = false;
- }
- }
-
- public function addSound(param1:String, param2:Sound, param3:uint, param4:uint) : *
- {
- sounds[param1] = new SoundObject(param1,param2,param3,param4);
- }
-
- public function purgeAll() : *
- {
- var _loc1_:String = null;
- for(_loc1_ in sounds)
- {
- purgeSound(_loc1_);
- }
- }
-
- public function playSound(param1:String) : *
- {
- var _loc2_:SoundChannel = null;
- var _loc3_:SoundObject = null;
- var _loc4_:SoundTransform = null;
- _loc2_ = null;
- if(isMute)
- {
- return _loc2_;
- }
- _loc3_ = sounds[param1];
- _loc4_ = new SoundTransform();
- if(_loc3_.Position == SoundObject.C_RIGHT)
- {
- _loc4_.pan = 1;
- }
- else if(_loc3_.Position == SoundObject.C_LEFT)
- {
- _loc4_.pan = -1;
- }
- else
- {
- _loc4_.pan = 0;
- }
- if(_loc3_.Type == SoundObject.C_BG && isBGPlaying && param1 != bgPlayingName)
- {
- stopBG();
- _loc4_.volume = bgVolume;
- bgSoundChannel = _loc3_.SoundData.play(0,int.MAX_VALUE,_loc4_);
- bgPlayingName = param1;
- isBGPlaying = true;
- _loc2_ = bgSoundChannel;
- }
- else if(_loc3_.Type == SoundObject.C_SFX)
- {
- _loc4_.volume = sfxVolume;
- _loc2_ = _loc3_.SoundData.play(0,0,_loc4_);
- }
- return _loc2_;
- }
-
- public function set SFXVolume(param1:Number) : *
- {
- sfxVolume = param1;
- }
- }
- }
-